package(default_visibility = ["//visibility:public"])

load(
    "@rules_haskell//haskell:defs.bzl",
    "haskell_binary",
    "haskell_library",
    "haskell_test",
)
load(
    "@rules_haskell//haskell:cabal.bzl",
    "haskell_cabal_binary",
    "haskell_cabal_library",
)
load(
    "//:build/common.bzl",
    "EXECUTABLE_FLAGS",
    "GHC_FLAGS",
)
load(
    "//:build/example_repos.bzl",
    "SEMANTIC_EXTERNAL_TEST_REPOSITORIES",
)

semantic_common_dependencies = [
    "//:bytestring",
    "//:containers",
    "//:process",
    "//:text",
    "//semantic-analysis",
    "//semantic-ast",
    "//semantic-source",
    "@stackage//:aeson",
    "@stackage//:algebraic-graphs",
    "@stackage//:async",
    "@stackage//:directory",
    "@stackage//:fused-effects",
    "@stackage//:fused-effects-exceptions",
    "@stackage//:hashable",
    "@stackage//:network",
    "@stackage//:pathtype",
    "@stackage//:recursion-schemes",
    "@stackage//:safe-exceptions",
    "@stackage//:scientific",
    "@stackage//:semilattices",
    "@stackage//:streaming",
    "@stackage//:unix",
]

haskell_library(
    name = "semantic",
    srcs = glob(["src/**/*.hs"]),
    compiler_flags = GHC_FLAGS + ["-XStrictData"],
    version = "0.11.0.1",
    deps = semantic_common_dependencies + [
        "//:base",
        "//:deepseq",
        "//:filepath",
        "//:template-haskell",
        "//semantic-codeql",
        "//semantic-go",
        "//semantic-java",
        "//semantic-json",
        "//semantic-php",
        "//semantic-proto",
        "//semantic-python",
        "//semantic-ruby",
        "//semantic-scope-graph",
        "//semantic-tags",
        "//semantic-tsx",
        "//semantic-typescript",
        "//:ghc-prim",
        "@stackage//:ansi-terminal",
        "@stackage//:attoparsec",
        "@stackage//:bifunctors",
        "@stackage//:directory-tree",
        "@stackage//:fused-syntax",
        "@stackage//:generic-lens",
        "@stackage//:haskeline",
        "@stackage//:hostname",
        "@stackage//:hscolour",
        "@stackage//:lens",
        "@stackage//:network-uri",
        "@stackage//:optparse-applicative",
        "@stackage//:parsers",
        "@stackage//:pretty-show",
        "@stackage//:prettyprinter",
        "@stackage//:proto-lens",
        "@stackage//:proto-lens-runtime",
        "@stackage//:reducers",
        "@stackage//:semigroupoids",
        "@stackage//:split",
        "@stackage//:stm-chans",
        "@stackage//:time",
        "@stackage//:tree-sitter",
        "@stackage//:tree-sitter-tsx",
        "@stackage//:unordered-containers",
        "@stackage//:vector",
    ],
)

haskell_binary(
    name = "exe",
    srcs = glob(["app/**/*.hs"]),
    compiler_flags = GHC_FLAGS + EXECUTABLE_FLAGS + ["-XStrictData"],
    deps = [
        ":semantic",
        "//:base",
        "//:filepath",
        "//semantic-analysis",
        "//semantic-proto",
        "@stackage//:optparse-applicative",
        "@stackage//:unix",
    ],
)

haskell_binary(
    name = "bench",
    srcs = glob(["bench/**/*.hs"]),
    compiler_flags = GHC_FLAGS + EXECUTABLE_FLAGS,
    deps = [
        ":semantic",
        "//:base",
        "//semantic-analysis",
        "//semantic-proto",
        "@stackage//:Glob",
        "@stackage//:fused-effects",
        "@stackage//:gauge",
        "@stackage//:pathtype",
    ],
)

haskell_test(
    name = "spec",
    srcs = glob(
        include = ["test/**/*.hs"],
        exclude = [
            "test/fixtures/**/*.hs",
            "test/Examples.hs",
            "test/System/Path/Fixture.hs",
        ],
    ),
    compiler_flags = GHC_FLAGS + EXECUTABLE_FLAGS + [
        "-XStrictData",
    ],
    data = glob(include = [
        "test/fixtures/**/*.json",
        "test/fixtures/go/**/*.go",
        "test/fixtures/python/**/*.py",
        "test/fixtures/ruby/**/*.rb",
        "test/fixtures/javascript/**/*.js",
        "test/fixtures/typescript/**/*.ts",
        "test/fixtures/cli/*.json",
    ]),
    deps = semantic_common_dependencies + [
        "//:base",
        "//semantic",
        "//semantic-proto",
        "//semantic-json",
        "//semantic-tags",
        "@stackage//:Glob",
        "@stackage//:HUnit",
        "@stackage//:bazel-runfiles",
        "@stackage//:bifunctors",
        "@stackage//:hedgehog",
        "@stackage//:hspec",
        "@stackage//:hspec-core",
        "@stackage//:hspec-expectations",
        "@stackage//:tasty",
        "@stackage//:tasty-golden",
        "@stackage//:tasty-hedgehog",
        "@stackage//:tasty-hspec",
        "@stackage//:tasty-hunit",
        "@stackage//:temporary",
        "@stackage//:tree-sitter",
    ],
)

haskell_test(
    name = "parse-examples",
    srcs = [
        "test/Examples.hs",
    ],
    compiler_flags = GHC_FLAGS + EXECUTABLE_FLAGS + [
        "-XStrictData",
    ],
    data = glob(include = [
        "test/fixtures/**/*.json",
        "test/fixtures/go/**/*.go",
        "test/fixtures/python/**/*.py",
        "test/fixtures/ruby/**/*.rb",
        "test/fixtures/javascript/**/*.js",
        "test/fixtures/typescript/**/*.ts",
        "test/fixtures/cli/*.json",
    ]) + SEMANTIC_EXTERNAL_TEST_REPOSITORIES,
    deps = semantic_common_dependencies + [
        "//:base",
        "//semantic",
        "//semantic-proto",
        "@stackage//:Glob",
        "@stackage//:bazel-runfiles",
        "@stackage//:lens",
        "@stackage//:tasty",
        "@stackage//:tasty-hunit",
    ],
)
